package com.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.bean.CityGoCount;
import com.bean.CountryGoCount;
import com.dao.StarGoCountDao;
import com.service.StarGoCountService;
import com.util.LoggerUtil;

@Component
public class StarGoCountServiceImpl implements StarGoCountService{
	public static Logger logger=Logger.getLogger(StarGoCountServiceImpl.class);
	@Autowired
	private StarGoCountDao starGoCountDao;

	@Override
	public Map<String, Object> selectSortByComment(JSONObject logs) {
		Map<String, Object> map=new HashMap<String, Object>();
		try {
			List<CityGoCount> pager=starGoCountDao.selectSortByComment();
			if(pager!=null&&pager.size()>0){
				map.put("result", "success");
				map.put("rows", pager);
				LoggerUtil.backlogsSuccess(logs, logger);
			}else{
				map.put("result", "false");
				LoggerUtil.backlogsFalseNOData(logs, logger);
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}

	@Override
	public Map<String, Object> selectByACont(String aCont,JSONObject logs) {
		Map<String, Object> map=new HashMap<String, Object>();
		try {
			List<CountryGoCount> data=starGoCountDao.selectByACont(aCont);
			if(data!=null&&data.size()>0){
				map.put("result", "success");
				map.put("rows", data);
				LoggerUtil.backlogsSuccess(logs, logger);
			}else{
				map.put("result", "false");
				LoggerUtil.backlogsFalseNOData(logs, logger);
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		
		return map;
	}

	@Override
	public Map<String, Object>selectByACount (String areaId,String userId,JSONObject logs) {
		Map<String, Object> map=new HashMap<String, Object>();
		try {
			Object pager=starGoCountDao.selectByACount(areaId,userId);
			if(pager!=null){
				map.put("result", "success");
				map.put("rows", pager);
				LoggerUtil.backlogsSuccess(logs, logger);
			}else{
				map.put("result", "false");
				LoggerUtil.backlogsFalseNOData(logs, logger);
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}

	@Override
	public Map<String, Object> selectByCuntryId(String countryId,JSONObject logs) {
		Map<String, Object> map=new HashMap<String, Object>();
		try {
			List<CityGoCount> pager=starGoCountDao.selectByCuntryId(countryId);
			
			if(pager!=null&&pager.size()>0){
				map.put("result", "success");
				map.put("rows", pager);
				LoggerUtil.backlogsSuccess(logs, logger);
			}else{
				map.put("result", "false");
				LoggerUtil.backlogsFalseNOData(logs, logger);
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}

	
}
